package mail

import (
	"config"
	"github.com/toolkits/smtp"
	"log"
)

func SendMail(subject string, content string) {
	sendMail(subject, content)
}

func sendMail(subject string, content string) {
	if config.EmailServerAddr == "" {
		log.Println("server addr can't be empty")
		return
	}

	if config.EmailUserName == "" {
		log.Println("email userName can't be empty")
		return
	}

	if config.EmailPassword == "" {
		log.Println("email password can't be empty")
		return
	}

	s := smtp.New(config.EmailServerAddr, config.EmailUserName, config.EmailPassword)
	err := s.SendMail(config.From, config.Tos, subject, content)
	if err != nil {
		log.Println("send email err: ", err)
	} else {
		log.Println("send email success")
	}
}

func Test() {
	SendMail("test email", "this is test notify")
}
